package com.api.controller

import com.aliyun.dysmsapi20170525.Client
import com.aliyun.dysmsapi20170525.models.SendSmsRequest
import com.aliyun.teaopenapi.models.Config
import com.aliyun.teautil.models.RuntimeOptions
import com.api.config.APIConfig
import com.base.config.BaseConfig
import com.base.db.mysql.*
import com.base.db.redis.cache_addCode_sms
import com.base.db.redis.cache_getCode_pic
import com.base.db.redis.cache_getCode_sms
import com.base.db.redis.cache_getToken_refresh
import com.base.model.api.*
import com.base.utils.DES
import com.base.utils.RandomUtils
import com.base.utils.toYuan
import com.base.utils.yToInt
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import org.springframework.http.HttpStatus

class Controller_API_App private constructor() {
    companion object {
        val instance by lazy(LazyThreadSafetyMode.SYNCHRONIZED) { Controller_API_App() }
    }

    //线路心跳
    fun Controller_API.APP_00A01(params: Map<*, *>) = yResult()

    //获取短信验证码
    fun Controller_API.APP_00A02(params: Map<*, *>): String {
        val phone = params["phone"]?.toString()
        if (phone.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val code = RandomUtils.run("0123456789", 6)
        redisService.cache_addCode_sms(APIFrom.App, phone, code)
        val response = Client(Config().setAccessKeyId(APIConfig.ali_AccessKeyId).setAccessKeySecret(APIConfig.ali_AccessKeySecret).setEndpoint("dysmsapi.aliyuncs.com")).sendSmsWithOptions(SendSmsRequest().setSignName("YShop").setTemplateCode("SMS_154950909").setPhoneNumbers(phone).setTemplateParam(gson.toJson(mapOf("code" to code))), RuntimeOptions())
        if (response.statusCode != HttpStatus.OK.value()) return yResult(code = -1, message = "验证码发送失败，statusCode：${response.statusCode}")
        if (response.body.code != "OK") return yResult(code = -1, message = "验证码发送失败，message：${response.body.message}")
        return yResult()
    }

    //获取服务协议
    fun Controller_API.APP_00A03(params: Map<*, *>): String {
        val model = ContentModel()
        model.content = "服务协议内容"
        return yResult(result = listOf(model))
    }

    //刷新sign
    fun Controller_API.APP_01A00(params: Map<*, *>): String {
        val refreshToken = _getRefreshToken()
        if (refreshToken.isNullOrBlank()) return yResult(code = -1, message = "签名不合法")
        val uid = redisService.cache_getToken_refresh(APIFrom.App, refreshToken)
        if (uid.isNullOrBlank()) return yResult(code = -1, message = "签名过期")
        return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
    }

    //登录_账号
    fun Controller_API.APP_01A01(params: Map<*, *>): String {
        val password = params["password"]?.toString()
        val loginname = params["loginname"]?.toString()
        val code = params["code"]?.toString()
        if (password.isNullOrEmpty() || loginname.isNullOrEmpty() || code.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        if (password.length < 6) return yResult(code = -1, message = "密码至少6位")
        if (loginname.length < 6) return yResult(code = -1, message = "用户名至少6位")
        if (redisService.cache_getCode_pic(this, loginname) != code.toLowerCase()) return yResult(code = -1, message = "验证码错误")
        val uid = mysqlService.app_getUserByAccount(loginname, encodePassword(password))
        if (uid.isNullOrEmpty()) return yResult(code = -1, message = "密码错误")
        return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
    }

    //登录_手机号
    fun Controller_API.APP_01A02(params: Map<*, *>): String {
        val phone = params["phone"]?.toString()
        val code = params["code"]?.toString()
        val type = params["type"]?.toString()
        if (phone.isNullOrEmpty() || code.isNullOrEmpty() || type.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        when (type) {
            "server" -> {
                if (redisService.cache_getCode_sms(APIFrom.App, phone) != code) return yResult(code = -1, message = "验证码错误")
                val uid = mysqlService.app_getUserByPhone(phone)
                if (uid.isNullOrEmpty()) return yResult(code = -1, message = "用户不存在，且创建失败")
                return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
            }

            "sdk" -> {
                if (!mobService.verify(phone, code)) return yResult(code = -1, message = "验证码错误")
                val uid = mysqlService.app_getUserByPhone(phone)
                if (uid.isNullOrEmpty()) return yResult(code = -1, message = "用户不存在，且创建失败")
                return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
            }

            else -> return yResult(code = -1, message = "尚未支持的验证方式")
        }
    }

    //登录_三方
    fun Controller_API.APP_01A03(params: Map<*, *>): String {
        val platform = params["platform"]?.toString()
        val thirdID = params["thirdID"]?.toString()
        if (platform.isNullOrEmpty() || thirdID.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val platform_columnName = when (platform) {
            "qq" -> "third_id_qq"
            "wechatSession" -> "third_id_wechat"
            else -> null
        }
        if (platform_columnName.isNullOrEmpty()) return yResult(code = -1, message = "不支持的三方平台")
        val uid = mysqlService.app_getUserByThird(platform_columnName, thirdID)
        if (uid.isNullOrEmpty()) return yResult(code = -1, message = "用户不存在，且创建失败")
        return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
    }

    //登录_免验证码登录
    fun Controller_API.APP_01A04(params: Map<*, *>): String {
        val opToken = params["opToken"]?.toString()
        val operator = params["operator"]?.toString()
        val token = params["token"]?.toString()
        if (opToken.isNullOrEmpty() || operator.isNullOrEmpty() || token.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val res = mobService.sdkClientFreeLogin(opToken, operator, token)
        if (res.isNullOrEmpty()) return yResult(code = -1, message = "验证错误1")
        val result_phone = gson.fromJson(String(DES.decode(res.toByteArray(), APIConfig.ali_AccessKeySecret.toByteArray())), Map::class.java)
        if (result_phone == null || result_phone["isValid"] != 1 || result_phone["valid"] != "true") return yResult(code = -1, message = "验证错误2")
        val phone = result_phone["phone"].toString()
        val uid = mysqlService.app_getUserByPhone(phone)
        if (uid.isNullOrEmpty()) return yResult(code = -1, message = "用户不存在，且创建失败")
        return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
    }

    //注册
    fun Controller_API.APP_01A05(params: Map<*, *>): String {
        val loginname = params["loginname"]?.toString()
        val password = params["password"]?.toString()
        val code = params["code"]?.toString()
        if (loginname.isNullOrEmpty() || password.isNullOrEmpty() || code.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        if (loginname.length < 6) return yResult(code = -1, message = "用户名至少6位")
        if (password.length < 6) return yResult(code = -1, message = "密码至少6位")
        if (redisService.cache_getCode_pic(this, loginname) != code.toLowerCase()) return yResult(code = -1, message = "验证码错误")
        if (mysqlService.app_checkUserIsExistByUserName(loginname)) return yResult(code = -1, message = "用户已存在")
        if (!mysqlService.app_addUserByAccountPassword(loginname, encodePassword(password))) return yResult(code = -1, message = "创建用户失败")
        return yResult()
    }

    //获取账号绑定状态
    fun Controller_API.APP_01A06(params: Map<*, *>): String {
        val uid = _getUID()
        if (uid.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val result = mysqlService.app_getUserBindStatusByID(uid)
        if (result == null) return yResult(code = -1, message = "查询结果为空")
        return yResult(result = listOf(result))
    }

    //修改密码
    fun Controller_API.APP_01A07(params: Map<*, *>): String {
        val password = params["password"]?.toString()
        if (password.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        if (password.length < 6) return yResult(code = -1, message = "密码至少6位")
        val uid = _getUID()!!
        if (!(mysqlService.app_checkUserIsExistByUidPassword(uid, encodePassword(password)))) return yResult(code = -1, message = "旧密码错误，或非账号登录用户")
        val password_new = params["password_new"]?.toString()
        if (password_new.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        if (password_new.length < 6) return yResult(code = -1, message = "密码至少6位")
        if (!mysqlService.app_updateUserByAccount(uid, encodePassword(password_new))) return yResult(code = -1, message = "密码修改失败")
        return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
    }

    //绑定_手机号
    fun Controller_API.APP_01A08(params: Map<*, *>): String {
        val phone = params["phone"]?.toString()
        val code = params["code"]?.toString()
        val type = params["type"]?.toString()
        if (phone.isNullOrEmpty() || code.isNullOrEmpty() || type.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val uid = _getUID()!!
        when (type) {
            "server" -> {
                if (redisService.cache_getCode_sms(APIFrom.App, phone) != code) return yResult(code = -1, message = "验证码错误")
                if (!mysqlService.app_updateUserByPhone(uid, phone)) return yResult(code = -1, message = "绑定失败")
                return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
            }

            "sdk" -> {
                if (!mobService.verify(phone, code)) return yResult(code = -1, message = "验证码错误")
                if (!mysqlService.app_updateUserByPhone(uid, phone)) return yResult(code = -1, message = "绑定失败")
                return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
            }

            else -> return yResult(code = -1, message = "尚未支持的验证方式")
        }
    }

    //绑定_三方
    fun Controller_API.APP_01A09(params: Map<*, *>): String {
        val platform = params["platform"]?.toString()
        val thirdID = params["thirdID"]?.toString()
        if (platform.isNullOrEmpty() || thirdID.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val platform_columnName = when (platform) {
            "qq" -> "third_id_qq"
            "wechatSession" -> "third_id_wechat"
            else -> null
        }
        if (platform_columnName.isNullOrEmpty()) return yResult(code = -1, message = "不支持的三方平台")
        val uid = _getUID()!!
        if (!mysqlService.app_updateUserByThird(uid, platform_columnName, thirdID)) return yResult(code = -1, message = "绑定失败")
        return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
    }

    //绑定_免验证码登录
    fun Controller_API.APP_01A10(params: Map<*, *>): String {
        val opToken = params["opToken"]?.toString()
        val operator = params["operator"]?.toString()
        val token = params["token"]?.toString()
        if (opToken.isNullOrEmpty() || operator.isNullOrEmpty() || token.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val res = mobService.sdkClientFreeLogin(opToken, operator, token)
        if (res.isNullOrEmpty()) return yResult(code = -1, message = "验证错误1")
        val result_phone = gson.fromJson(String(DES.decode(res.toByteArray(), APIConfig.ali_AccessKeySecret.toByteArray())), Map::class.java)
        if (result_phone == null || result_phone["isValid"] != 1 || result_phone["valid"] != "true") return yResult(code = -1, message = "验证错误2")
        val phone = result_phone["phone"].toString()
        val uid = _getUID()!!
        if (!mysqlService.app_updateUserByPhone(uid, phone)) return yResult(code = -1, message = "绑定失败")
        return yResult(result = listOf(_getUserModelByUID(uid, APIFrom.App)))
    }

    //更新头像
    fun Controller_API.APP_01A11(params: Map<*, *>): String {
        val avatar = params["avatar"]?.toString()
        if (avatar.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val uid = _getUID()!!
        if (!mysqlService.app_updateUserAvatar(uid, avatar)) return yResult(code = -1, message = "头像更新失败")
        return yResult()
    }

    //更新昵称
    fun Controller_API.APP_01A12(params: Map<*, *>): String {
        val name = params["name"]?.toString()
        if (name.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val uid = _getUID()!!
        if (!mysqlService.app_updateUserName(uid, name)) return yResult(code = -1, message = "昵称更新失败")
        return yResult()
    }

    //获取首页推荐数据
    fun Controller_API.APP_02A01(params: Map<*, *>): String {
        val results_big = mysqlService.app_getHome_banners_big() ?: return yResult(code = -1, message = "查询失败1")
        val results_left = mysqlService.app_getHome_banners_left() ?: return yResult(code = -1, message = "查询失败2")
        val results_right = mysqlService.app_getHome_banners_right() ?: return yResult(code = -1, message = "查询失败3")
        val results_func = mysqlService.app_getHome_banners_func() ?: return yResult(code = -1, message = "查询失败4")
        val results_productItems = mysqlService.app_getHome_productItems(10) ?: return yResult(code = -1, message = "查询失败5")
        val result = ShouYeTJModel()
        result.funcs = results_func
        result.banners_big = results_big
        result.banners_small_left = results_left
        result.banners_small_right = results_right
        result.productItems = results_productItems
        return yResult(result = listOf(result))
    }

    //操作推荐敏感功能
    fun Controller_API.APP_02A02(params: Map<*, *>): String {
        return yResult()
    }

    //获取首页分类数据
    fun Controller_API.APP_02A03(params: Map<*, *>): String {
        val categorys = mysqlService.app_getCategory() ?: return yResult(code = -1, message = "查询失败")
        val results = arrayListOf<ShouYeFLModel>()
        categorys.forEach { category ->
            if (category.parent == null) {
                val groups = arrayListOf<ShouYeFLModel.ShouYeFLModel_Group>()
                categorys.forEach { category2 ->
                    if (category2.parent == category.id) {
                        val items = arrayListOf<ShouYeFLModel.ShouYeFLModel_Group.ShouYeFLModel_Item>()
                        categorys.forEach { category3 ->
                            if (category3.parent == category2.id) {
                                items.add(category3)
                            }
                        }
                        val group = ShouYeFLModel.ShouYeFLModel_Group()
                        group.title = category2.title!!
                        group.items = items
                        groups.add(group)
                    }
                }
                val model = ShouYeFLModel()
                model.title = category.title!!
                model.isSelect = category.isSelect!!
                model.groups = groups
                results.add(model)
            }
        }
        return yResult(result = results)
    }

    //通过ID获取商品列表检索文字
//    fun Controller_API.APP_02A04(params: Map<*, *>): String {
//        return yResult()
//    }

    //商品列表
    fun Controller_API.APP_02A05(params: Map<*, *>): String {
        val page = params["page"]?.toString()?.yToInt()
        val content = params["content"]?.toString()
        val search = Gson().fromJson<List<ProductListModel.SearchMainModel>>(Gson().toJson(params["search"]), object : TypeToken<List<ProductListModel.SearchMainModel>>() {}.type)
        if (page == null || page <= 0) return yResult(code = -1, message = "参数不合法")
        val orderBy = search?.firstOrNull { it.id == "1" }?.items?.firstOrNull { it.isSelect == true }?.id ?: "1"
        val type = search?.firstOrNull { it.id == "2" }?.items?.firstOrNull { it.isSelect == true }?.id
        val productItems = mysqlService.app_getSPUs(content, page, 10, orderBy, type) ?: return yResult(code = -1, message = "查询不合法")
        val result = ProductListModel()
        result.productItems = productItems
        result.searchItems = Gson().fromJson("""[
            {
                "id": "1",
                "isSingle": true,
                "title": "综合",
                "value": "综合",
                "items": [
                    {"id": "1", "isSelect": true, "title": "综合"},
                    {"id": "2", "isSelect": false, "title": "销量"},
                    {"id": "3", "isSelect": false, "title": "价格降序"},
                    {"id": "4", "isSelect": false, "title": "价格升序"}
                ]
            },
            {
                "id": "2",
                "isSingle": false,
                "title": "类型",
                "value": "",
                "items": [
                    {"id": "1", "isSelect": false, "title": "类型1"},
                    {"id": "2", "isSelect": false, "title": "类型2"}
                ]
            }
        ]""".trimIndent(), object : TypeToken<List<ProductListModel.SearchMainModel>>() {}.type)
        return yResult(result = listOf(result))
    }

    //商品详情
    fun Controller_API.APP_02A06(params: Map<*, *>): String {
        val id = params["id"]?.toString()
        if (id.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val result = ProductDetailModel()
        val result_spu = mysqlService.app_getSPUDetailById(id)
        if (result_spu == null) return yResult(code = -1, message = "SPU不存在")
        result.title = result_spu["title"]?.toString()
        result.money = if (result_spu["money_min"] == result_spu["money_max"]) result_spu["money_min"].toYuan() else "${result_spu["money_min"].toYuan()}-${result_spu["money_max"].toYuan()}"
        result.count_sales = result_spu["count_sale"]?.toString()?.toInt()
        val items_assets = arrayListOf<ProductDetailModel.ProductDetailModel_Asset>()
        val video = result_spu["video"]?.toString()
        if (video != null && video.isNotEmpty()) {
            val asset_video = ProductDetailModel.ProductDetailModel_Asset()
            asset_video.video = video
            items_assets.add(asset_video)
        }
        items_assets.addAll((result_spu["img_banner"] as List<String>).map {
            val asset_image = ProductDetailModel.ProductDetailModel_Asset()
            asset_image.img = it
            return@map asset_image
        })
        result.items_assets = items_assets
        result.items_param = listOf("品牌", "型号", "是否可退换").mapIndexed { index, item ->
            val item_param = ProductDetailModel.ProductDetailModel_Param()
            item_param.title = item
            item_param.content = result_spu[listOf("params_pinpai", "params_xinghao", "params_tuihuan")[index]]?.toString()
            return@mapIndexed item_param
        }
        result.items_detail = result_spu["img_detail"] as List<String>
        val result_skus = mysqlService.app_getSKUsBySPUId(id)
        if (result_skus.isNullOrEmpty()) return yResult(code = -1, message = "SKU不存在")
        result.items_sku = result_skus.mapIndexed { index, it ->
            val item_sku = ProductDetailModel.ProductDetailModel_Sku()
            item_sku.id = it["id"]?.toString()
            item_sku.title = it["title"]?.toString()
            item_sku.img = it["img"]?.toString()
            item_sku.money = it["money"].toYuan()
            item_sku.count_left = it["count_left"]?.toString()?.toDouble()?.toInt()
            item_sku.count_sales = it["count_sales"]?.toString()?.toDouble()?.toInt()
            return@mapIndexed item_sku
        }
        result.items_sku!!.firstOrNull { it.count_left!! > 0 }?.isSelect = true
        val service = mysqlService.app_getService() ?: return yResult(code = -1, message = "客服不存在")
        result.serviceID = service["account"]?.toString()
        result.serviceName = service["name"]?.toString()
        result.serviceAvatar = service["avatar"]?.toString()
        val uid = _getUID()
        if (uid != null) {
            val userModelExt = mysqlService.app_getUserExtById(uid) ?: return yResult(code = -1, message = "用户不存在")
            if (userModelExt.collections != null) {
                result.isSave = userModelExt.collections!!.contains(id)
            } else {
                result.isSave = false
            }
            if (userModelExt.carts != null) {
                result.count_carts = userModelExt.carts!!.size
            } else {
                result.count_carts = 0
            }
        } else {
            result.isSave = false
            result.count_carts = 0
        }
        val count_replys = mysqlService.app_getReplyCountBySku(id) ?: return yResult(code = -1, message = "评论不存在")
        result.count_replys = count_replys
        return yResult(result = listOf(result))
    }

    //置反收藏商品
    fun Controller_API.APP_02A07(params: Map<*, *>): String {
        val id = params["id"]?.toString()
        if (id.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val userModelExt = mysqlService.app_getUserExtById(_getUID()!!) ?: return yResult(code = -1, message = "用户不存在")
        if (userModelExt.collections == null) userModelExt.collections = arrayListOf()
        if (userModelExt.collections!!.contains(id)) {
            userModelExt.collections!!.remove(id)
        } else {
            userModelExt.collections!!.add(id)
        }
        if (!mysqlService.app_updateUserExtById(_getUID()!!, collections = userModelExt.collections)) return yResult(code = -1, message = "操作失败")
        val result = ProductDetailModel()
        result.isSave = userModelExt.collections!!.contains(id)
        return yResult(result = listOf(result))
    }

    //立即购买，临时生成购物车格式数据，不加入购物车，无购物车ID，供确认订单前调用
    fun Controller_API.APP_02A09(params: Map<*, *>): String {
        return yResult(result = Gson().fromJson("""[
                            {"spu": "1", "sku": "1", "title_product": "标题1", "title_type": "规格1", "img": "${BaseConfig.ossBaseURL_temp}/a.webp", "money": "165", "count_left": "0"},
                            {"spu": "2", "sku": "2", "title_product": "标题2", "title_type": "规格2", "img": "${BaseConfig.ossBaseURL_temp}/b.webp", "money": "9985", "count_left": "5"}
                        ]""".trimIndent(), object : TypeToken<List<CartListModel.CartMainModel>>() {}.type))
    }

    //获取购物车列表
    fun Controller_API.APP_03A01(params: Map<*, *>): String {
        val userModelExt = mysqlService.app_getUserExtById(_getUID()!!) ?: return yResult(code = -1, message = "用户不存在")
        if (userModelExt.carts == null) userModelExt.carts = arrayListOf()
        val items_carts = mysqlService.app_getCartBySku(userModelExt.carts!!) ?: return yResult(code = -1, message = "查询失败")
        val result = CartListModel()
        result.count_carts = items_carts.size
        result.items_carts = items_carts
        return yResult(result = listOf(result))
    }

    //添加购物车
    fun Controller_API.APP_03A02(params: Map<*, *>): String {
        val spu = params["spu"]?.toString()
        val sku = params["sku"]?.toString()
        val count = params["count"]?.toString()
        if (spu.isNullOrEmpty() || sku.isNullOrEmpty() || count.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val userModelExt = mysqlService.app_getUserExtById(_getUID()!!) ?: return yResult(code = -1, message = "用户不存在")
        if (userModelExt.carts == null) userModelExt.carts = arrayListOf()
        if (userModelExt.carts!!.contains(sku)) return yResult(code = -1, message = "该商品已经在购物车中")
        userModelExt.carts!!.add(sku)
        if (!mysqlService.app_updateUserExtById(_getUID()!!, carts = userModelExt.carts)) return yResult(code = -1, message = "操作失败")
        val result = ProductDetailModel()
        result.count_carts = userModelExt.carts!!.size
        return yResult(result = listOf(result))
    }

    //删除购物车
    fun Controller_API.APP_03A03(params: Map<*, *>): String {
        val sku = params["sku"]?.toString()
        if (sku.isNullOrEmpty()) return yResult(code = -1, message = "数据不合法")
        val userModelExt = mysqlService.app_getUserExtById(_getUID()!!) ?: return yResult(code = -1, message = "用户不存在")
        if (userModelExt.carts == null) userModelExt.carts = arrayListOf()
        if (!userModelExt.carts!!.contains(sku)) return yResult(code = -1, message = "该商品不存在购物车中")
        userModelExt.carts!!.remove(sku)
        if (!mysqlService.app_updateUserExtById(_getUID()!!, carts = userModelExt.carts)) return yResult(code = -1, message = "操作失败")
        return yResult()
    }

    //随机获取五个短视频
    fun Controller_API.APP_04A01(params: Map<*, *>): String {
        val results = mysqlService.app_getVideos(5) ?: return yResult(code = -1, message = "查询失败")
        return yResult(result = results)
    }

    //发布短视频
    fun Controller_API.APP_04A02(params: Map<*, *>): String {
        val video = params["video"]?.toString()
        if (video.isNullOrEmpty()) return yResult(code = -1, message = "参数不合法")
        val uid = _getUID()!!
        if (!mysqlService.app_addVideo(uid, video)) return yResult(code = -1, message = "插入失败")
        return yResult()
    }

    //获取评论列表
    fun Controller_API.APP_05A01(params: Map<*, *>): String {
        val spu = params["spu"]?.toString()
        val page = params["page"]?.toString()?.toIntOrNull()
        if (spu.isNullOrEmpty() || page == null || page <= 0) return yResult(code = -1, message = "参数不合法")
        val results = mysqlService.app_getReplysBySku(spu, page, 10) ?: return yResult(code = -1, message = "查询失败")
        return yResult(result = results)
    }
}
